package remoto;

import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class BusinessServer {
	
	    
	    public void publicarServicio() {
	    	try {
	    		InterfazRemota remota = new GestionRemota();
	    		InterfazRemota stub = (InterfazRemota) UnicastRemoteObject.exportObject(remota, 0);
				LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
				Naming.rebind("//localhost/Sistema", stub);
	            verVinculos();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
	    
	    public void verVinculos() {
	        try {
	      	  String[] vinculos = Naming.list( "" );
	      	  System.out.println(InetAddress.getLocalHost().getHostAddress());
	      	  for ( int i = 0; i < vinculos.length; i++ ){
	      		System.out.print( "\n"+vinculos[i] );
	      	  }
	        }
	        catch (Exception e) {
	      	  e.printStackTrace();
	        }
	     }
	    
	    public void cerrar() {
			try {
				Naming.unbind("Sistema");
			} catch (Exception e) {
			} finally {
				System.exit(0);
			}
	    }


}
